import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import {PageInfo, Student, TongjiSex} from "./student";
import {Observable} from "rxjs";
const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable({
  providedIn: 'root'
})

export class StudentService {
  private uri="api/student/";
  constructor(private http: HttpClient) { }
  save(student:Student){
    this.http.post<Student>(`${this.uri}save`,student,httpOptions).pipe().subscribe(s =>student.id=s.id)
  }
  list(pageNum:number,pageSize:number):Observable<PageInfo>{
    var paination = {
      pageNum:pageNum,
      pageSize:pageSize
    };
    return this.http.post<PageInfo>(`${this.uri}list`,paination,httpOptions).pipe()
  }
  sex():Observable<TongjiSex[]>{
    return this.http.get<TongjiSex[]>(`${this.uri}sex`).pipe()
  }
}


